package org.webscale.util.sqs;

import org.apache.log4j.Logger;
import org.webscale.ApplicationException;
import org.webscale.util.AWSCredential;

import com.xerox.amazonws.sqs2.MessageQueue;
import com.xerox.amazonws.sqs2.SQSException;
import com.xerox.amazonws.sqs2.SQSUtils;

public class SQSHelper {
	private static final Logger log = Logger.getLogger(SQSHelper.class);
	AWSCredential credentials;
	private String queue;
	
	public void putMessage(String message){
		  MessageQueue msgQueue;
		try {
			msgQueue = SQSUtils.connectToQueue(queue, credentials.getAwsKey(), credentials.getAwsSecretKey());
	       String msgId = msgQueue.sendMessage(message );
          log.debug(" url returned = "+msgQueue.getUrl());
		} catch (SQSException e) {
		  log.error(e);
		  throw new ApplicationException(e);
		}
	}

	public AWSCredential getCredentials() {
		return credentials;
	}

	public void setCredentials(AWSCredential credentials) {
		this.credentials = credentials;
	}

	public String getQueue() {
		return queue;
	}

	public void setQueue(String queue) {
		this.queue = queue;
	}
	
	
	
}
